package com.hhh.petadopt.serviceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hhh.petadopt.mapper.AdminAdoptMapper;
import com.hhh.petadopt.pojo.Adopt;
import com.hhh.petadopt.pojo.AdoptVo;
import com.hhh.petadopt.service.AdminAdoptService;
import com.hhh.petadopt.utils.MailUtils;
import com.hhh.petadopt.utils.Page;
/**
 * 收养管理
 * @author 杜镇声声
 *
 */
@Service
public class AdminAdoptServiceImpl implements AdminAdoptService {
	
	@Autowired
	private AdminAdoptMapper adminadoptmapper;

	//显示收养管理页面
	@Override
	public Page<Adopt> selectAdopt(AdoptVo Vo) {
		//创建page对象
		Page<Adopt> page = new Page<Adopt>();
		//封装数据
		page.setSize(10);
		Vo.setSize(10);
		if(null != Vo) {
			//判断当前页是否为空
			if(null != Vo.getPage()) {
				//不为空,设置当前页
				page.setPage(Vo.getPage());
				//设置起始页
				Vo.setStartRow((Vo.getPage()-1)*Vo.getSize());
			}
			//判断输入框数据是否为空
			if(null != Vo.getNumm() && !"".equals(Vo.getNumm().trim())) {
				//不为空,并且不等于空串
				Vo.setNumm(Vo.getNumm().trim());
			}
			if(null != Vo.getIspass() && !"".equals(Vo.getIspass().trim())) {
				Vo.setIspass(Vo.getIspass().trim());
			}
			//查询符合条件的总条数,封装起来
			page.setTotal(adminadoptmapper.selectTotal(Vo));
			//查询符合条件的内容,封装起来
			page.setRows(adminadoptmapper.selectAdoptListByVo(Vo));
		}
		return page;
	}

	//通过审核
	@Override
	public void passw(Integer id) {
		adminadoptmapper.passw(id);
		Adopt adopt = adminadoptmapper.selectAdoptById(id);
		//通知信息
		String emailMsg = adopt.getAdoptman()+"您好! 您收养的宠物"+adopt.getAdoptname()+",编号:"+adopt.getAdoptnum()+"已通过审核。"
				+"请在一周之内带相关证件前往办理收养收养手续!如有疑问请电话咨询:"+"123456";
		//发邮件通知
		try {
			MailUtils.sendMail(adopt.getAdoptemail(), emailMsg);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	//取消通过
	@Override
	public void cancelPass(Integer id) {
		adminadoptmapper.cancelallow(id);
		Adopt adopt = adminadoptmapper.selectAdoptById(id);
		String emailMsg = adopt.getAdoptman()+"您好! 很遗憾通知您,您收养的宠物"+adopt.getAdoptname()+",编号:"+adopt.getAdoptnum()+"被取消通过。"
				+"如有疑问请电话咨询:"+"123456";
		//发邮件
		try {
			MailUtils.sendMail(adopt.getAdoptemail(), emailMsg);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	//根据id删除 
	@Override
	public void deleteAdoptById(Integer id) {
		adminadoptmapper.deleteadoptById(id);
		
	}

	//删除多选
	@Override
	public void deleteAdoptSByIds(Integer[] ids) {
		//执行删除
		adminadoptmapper.deleteAdoptsByIds(ids);
		
	}
	

}
